package com.cloud.logger.zchain.zchainclient.http;/*
package com.cloud.logger.zchain.zchainclient.http;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONException;
import com.alibaba.fastjson.JSONObject;
import org.apache.commons.lang.StringUtils;
import org.apache.http.NameValuePair;
import org.apache.http.client.entity.UrlEncodedFormEntity;
import org.apache.http.client.methods.*;
import org.apache.http.client.utils.URIBuilder;
import org.apache.http.entity.StringEntity;

import java.io.UnsupportedEncodingException;
import java.net.URISyntaxException;
import java.util.ArrayList;
import java.util.Map;

import static org.apache.commons.codec.CharEncoding.UTF_8;


*/
/**
 * Created by Administrator on 2017/12/14 0014.
 *//*

public class DynameicConversion<T> {
    //这里需要把泛型的状态传过来，所以有两个T
    public T doDynameic(T obj, String method, String url, T params) {
        T tBackContent = null;
        //做保护
        if (null != obj && !"".equals(obj)) {
            tBackContent = dowell(obj, method, url, params);
        } else {
            //打印日志，并返回参数，
            Object tBackContent1 = JSONObject.parseObject("{\"errCode\":\"8500\",\"errMessage\":\"参数不能为空\"}", params.getClass());
            return (T) tBackContent1;
        }
        return tBackContent;
    }

    private T dowell(T obj, String method, String url, T params) {
        JSONObject jsonObject;
        String strTemp = JSONObject.toJSONString(obj);
        jsonObject = JSON.parseObject(strTemp);
        String result = returnDataRequest(method, url, jsonObject);
        Object resultFinaly;
        try {
            resultFinaly = JSON.parseObject(result, params.getClass());
        } catch (JSONException e) {
            e.printStackTrace();
            return null;
        }
        return (T) resultFinaly;
    }


    //判断执行哪个方法
    public static String returnDataRequest(String method, String url, JSONObject jSONObject) {
        RestClientTemplate restClientTemplate = new RestClientTemplate();
        String result = null;
        if (method.equals("doGetRequest")) {
            URIBuilder ub = new URIBuilder();
            ub.setPath(url);
            ArrayList<NameValuePair> pairs = restClientTemplate.covertParams2NVPS(jSONObject);
            ub.setParameters(pairs);
            HttpGet httpGet = null;
            try {
                httpGet = new HttpGet(ub.build());
            } catch (URISyntaxException e) {
                e.printStackTrace();
                return "{\"errCode\":\"8500\"}";
            }
            result = restClientTemplate.getResult(httpGet, null);
        } else if (method.equals("doGetRequestAddHeader")) {
            URIBuilder ub = new URIBuilder();
            ub.setPath(url);
            ArrayList<NameValuePair> pairs = restClientTemplate.covertParams2NVPS(jSONObject);
            ub.setParameters(pairs);
            HttpGet httpGet = null;
            try {
                httpGet = new HttpGet(ub.build());
            } catch (URISyntaxException e) {
                e.printStackTrace();
                return "{\"errCode\":\"8500\"}";
            }
            JSONObject headers = (JSONObject) jSONObject.get("headers");
            for (Map.Entry<String, Object> param : headers.entrySet()) {
                httpGet.addHeader(param.getKey(), String.valueOf(param.getValue()));
            }
            result = restClientTemplate.getResult(httpGet, jSONObject);

        } else if (method.equals("doPut")) {
            HttpPut httpCurrency = new HttpPut(url);
            result = restClientTemplate.getResult(httpCurrency, jSONObject);
        } else if (method.equals("doPost")) {
            HttpPost httpCurrency = new HttpPost(url);
            httpCurrency.setHeader("Content-Type", "application/json");
            httpCurrency.setEntity(new StringEntity(jSONObject.toJSONString(), "UTF-8"));
            result = restClientTemplate.getResult(httpCurrency, jSONObject);
        } else if (method.equals("postForm")) {
            url = StringUtils.trimToEmpty(url);
            HttpPost httpPost = new HttpPost(url);
            ArrayList<NameValuePair> pairs = restClientTemplate.covertParams2NVPS((JSONObject) jSONObject);
            httpPost.setHeader("Content-Type", "application/x-www-form-urlencoded");
            try {
                httpPost.setEntity(new UrlEncodedFormEntity(pairs, UTF_8));
            } catch (UnsupportedEncodingException e) {
                e.printStackTrace();
                return "{\"errCode\":\"8500\"}";
            }
            result = restClientTemplate.getResult(httpPost, jSONObject);
        } else if (method.equals("doPatch")) {
            HttpPatch httpCurrency = new HttpPatch(url);
            result = restClientTemplate.getResult(httpCurrency, jSONObject);
        } else if (method.equals("doDelete")) {
            HttpDelete httpCurrency = new HttpDelete(url);
            result = restClientTemplate.getResult(httpCurrency, jSONObject);
        } else if (method.equals("HEADER ")) {
            //HEAD就像GET，只不过服务端接受到HEAD请求后只返回响应头，而不会发送响应内容。当我们只需要查看某个页面的状态的时候,
            // 使用HEAD是非常高效的，因为在传输的过程中省去了页面内容。
            HttpHead httpCurrency = new HttpHead(url);
            httpCurrency.addHeader("Accept", "text/html");
            result = restClientTemplate.getResult(httpCurrency, jSONObject);
        } else if (method.equals("OPTIONS ")) {
            HttpOptions httpCurrency = new HttpOptions(url);
            result = restClientTemplate.getResult(httpCurrency, jSONObject);
        } else if (method.equals("TRACE ")) {
            HttpTrace httpCurrency = new HttpTrace(url);
            result = restClientTemplate.getResult(httpCurrency, jSONObject);
        } else {
            return "{\"errCode\":\"8500\"}";
        }
        return result;
    }

}
*/
